<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page_setting');
	$params=array('mid'=>$_SESSION['uid']);
	if($isarea){
		$params['level']=16;
	}
	if($isxuni){
		$params['isxuni']=1;
		$return['jiesuannum']=$this->count('feelog',array('isxuni'=>1,'mid'=>$_SESSION['uid'],'status'=>1));
	}
	$return['commission_money']=$this->sum('feelog',$params,'fee');
	if(!$return['commission_money']){
		$return['commission_money']=0;
	}
	$return['commission_total']=$this->count('feelog',$params);
	$params['type']=20;
	unset($params['level']);
	$return['jichanum']=$this->count('feelog',$params);
	$levels=array();
	for($i=0;$i<$this->setting['level'];$i++){
		$level=$i+1;
		$levels[$i]['key']=$level;
		$levels[$i]['title']=$this->setting['levelname'.$level]?:$level.'级';
		$levels[$i]['num']=$this->count('feelog',array('mid'=>$_SESSION['uid'],'levelid'=>$level));
	}
	$return['levels']=$levels;
	$return['list']=array();
	$return['params']=array('type'=>intval($_RQ['type']));
	$return['psize']=20;
	set_html('title','奖励明细');
	$return['xuniname']=$this->xuniname;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('mid'=>$_SESSION['uid']);
	if($_RQ['type']){
		$params['type']=$_RQ['type'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('feelog',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['member']=model('core/member')->basic($item['ordermid']);
		$item['statustitle']=$this->commission_status[$item['status']];	
		$item['typetitle']=$this->commission_money_types[$item['type']];
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);
	}
	exi($list);
}
if($_RQ['op']=='xunibalance'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1,'isxuni'=>1);
	$money=pdo_getsum('jy_newczfee_commission',$params,'money');
	cfc('core')->member_credit($_SESSION['uid'],'credit'.$this->setting['credit_type'],$money,true,'jy_newczfee','分红奖励结算');
	$update=array(
		'status'=>2,
	);
	$this->update('commission',$update,$params);
	exi('结算成功！','','/index/');
}
?>